#include "../include/BusinessService.hpp"
#include "../include/Mylogger.hpp"
#include "../include/Message.hpp"
#include "../include/TCPConnection.hpp"

#include <string.h>

#include <iostream>
using std::cout;
using std::endl;

UserLoginSection1::UserLoginSection1(cdm::TCPConnectionPtr conn,cdm::Packet &packet)
:_conn(conn),
_packet(packet){

}

void UserLoginSection1::process(){
    //todo:查询数据库，判断用户是否存在
    cdm::TLV data;
    if(_packet._msg == "tanggoudan"){
        //用户存在，获取盐值并返回
        //todo: 获取获取数据库tanggoudan对应的盐值
        LOG_INFO("find user");
        const char * salt = "tgdd2211";
        data.type = cdm::TASK_LOGIN1_RESP_OK;
        data.length = strlen(salt);
        strncpy(data.msg,salt,data.length);
        cout<<data.type<<endl<<data.length<<endl<<data.msg<<endl;
        _conn->sendInLoop(data);
        LOG_INFO("send salt to client success");

    }else{
        data.type = cdm::TASK_LOGIN1_RESP_ERROR;
        string res = "no this user";
        data.length = res.size();
        strncpy(data.msg,res.c_str(),data.length);
        cout<<data.type<<endl<<data.length<<endl<<data.msg<<endl;
        _conn->sendInLoop(data);
        LOG_INFO("not find tanggoudan");
    }

}

UserLoginSection2::UserLoginSection2(cdm::TCPConnectionPtr conn,cdm::Packet &packet)
:_conn(conn),
_packet(packet){

}

void UserLoginSection2::process(){
    //校对密码

}




